<template>
  <div class="feedbackPage">
    <el-form :inline="true" style="padding: 25px 10px">
      <el-form-item label="反馈类型:">
        <el-select v-model="queryForm.type" placeholder="请选择类型">
          <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="queryData">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="list" element-loading-text="正在加载...">
      <el-table-column label="反馈类型">
        <template #default="{ row }">
          {{ formatType(row.type) }}
        </template>
      </el-table-column>
      <el-table-column label="内容" prop="opinion" />
      <el-table-column label="图片" prop="opinion">
        <template #default="{ row }">
          <el-image v-for="item in row.imageIds" :key="item.id" class="imgStyle" :preview-src-list="[item.url]"
            :src="item.url" />
        </template>
      </el-table-column>

      <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button type="danger" text @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background :current-page="queryForm.pageNo" layout="total, sizes, prev, pager, next, jumper"
      :page-size="queryForm.pageSize" :total="total" @current-change="handleCurrentChange"
      @size-change="handleSizeChange" />
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  name: 'RoomManagement',
  data() {
    return {
      typeList: [
        {
          value: 'Unknown',
          label: '全部',
        },
        {
          value: 0,
          label: '软件建议/意见',
        },
        {
          value: 1,
          label: '软件使用异常',
        },
        {
          value: 2,
          label: '其他',
        },
      ],
      list: null,
      listLoading: true,
      total: 0,
      queryForm: {
        pageNo: 1,
        pageSize: 10,
        type: 'Unknown'
      },
    }
  },
  created() {
    this.fetchData()
  },

  methods: {
    handleSizeChange(val) {
      this.queryForm.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.queryForm.pageNo = val
      this.fetchData()
    },
    queryData() {
      this.queryForm.pageNo = 1
      this.fetchData()
    },

    async fetchData() {
      try {
        this.listLoading = true
        const params = { ...this.queryForm }
        if (
          params.type == 'Unknown') {
          delete params.type
        }
        const { data } = await request({
          url: '/house/api/opinion/get-opinion',
          method: 'get',
          params: params,
        })
        this.list = data.list
        this.total = data.totalCount
        this.listLoading = false
      } catch (error) {
        this.listLoading = false
      }
    },

    handleDelete(row) {
      this.$baseConfirm('你确定要删除当前项吗', null, async () => {
        try {
          await request({
            url: '/house/api/opinion/del-opinion',
            method: 'delete',
            data: { id: row.id },
          })
          this.$baseMessage('删除成功', 'success')
          this.queryData()
        } catch (error) { }
      })
    },

    // 获取类型
    formatType(type) {
      let result = '-'
      switch (type) {
        case 0:
          result = '软件建议/意见'
          break
        case 1:
          result = '软件使用异常'
          break
        case 2:
          result = '其他'
          break
        default:
          break
      }
      return result
    },
  },
}
</script>

<style lang="scss" scoped>
.imgStyle {
  width: 60px !important;
  height: 60px !important;
  margin-left: 5px;
}
</style>
